import React, { useEffect, useRef, useState } from 'react'

const [num,setNum]=useState(0)
const timer=useRef(null)
function Child() {

  useEffect(()=>{
    timer.current=setInterval(()=>{
      setNum((num)=>num+1)
    },1000)
    return ()=>{
      clearInterval(timer.current)
    }
  })

  return (
    <div>
      <h1>{num}</h1>
    </div>
  )
}

export default Child